﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hostal.Bussines.Repository.Service;
using Hostal.Bussines.Entities;

namespace Hostal.Bussines.Repository
{
   public  class TipoHabitacionRepository:MasterRepository,ITipoHabitacionRepository
    {
        public List<TipoHabitacione> GetAllFromTipodeHabitacion()
        {
            var query = from p in Context.TipoHabitacion
                        select p;

            return query.ToList();
        }

        public List<TipoHabitacione> GetFromTipoHabitacionByCriterio(string criterio)
        {
           var query = from c in Context.TipoHabitacion
                       select c;

           if (criterio != null && criterio != "")
           {
               query = from c in query
                       where c.Descripcion.ToUpper().Contains(criterio.ToUpper())
                       select c;
           }

           return query.ToList();
        }

        public TipoHabitacione GetFromTipoHabitacionById(Int32 id)
        {
            return Context.TipoHabitacion.Find(id);
        }

        public void AddTipoHabitacion(TipoHabitacione tipoHabitacion)
        {
            Context.TipoHabitacion.Add(tipoHabitacion);
            Context.SaveChanges();
        }

        public void UpdateTipoHabitacion(TipoHabitacione tipoHabitacion)
        {
            Context.Entry(tipoHabitacion).State = System.Data.EntityState.Modified;
            Context.SaveChanges();
        }

        public void RemoveTipoHabitacion(int id)
        {
            var existe = Context.TipoHabitacion.Where(h => h.IdHabitacion.Equals(id)).SingleOrDefault();

            if (existe != null)
            {
                Context.TipoHabitacion.Remove(existe);
                Context.SaveChanges();
            }
        }
    }
}
